
var isEmpty =function(obj) {
	if (typeof obj == "undefined" || obj == null || obj == "") {
		return true;
	} else {
		return false;
	}
}

var checkLoginState= function() {
	var token = uni.getStorageSync('AppToken');
	if (token ) {
		return true
	} else {
		return false
	}
}

var getDictLabelName= function(key,dictValue) {
	if(dictValue==null){
		return "";
	}
	var dicts = uni.getStorageSync('dicts');
	dicts=JSON.parse(dicts);
	var dict=dicts[key]
	var name="";
	dict.forEach(function(item, index, array) {
		 if(dictValue.toString()==item.dictValue.toString())
		 {
			 name=item.dictLabel
		 }
	});
	return name;
}


var photosToArr= function(photoUrl) {
	 var photos=[];
	 if(photoUrl!=null&&photoUrl!=''){
		 photos=photoUrl.split(',');
	 }
	 console.log(photos)
	 return photos
}

var dateFormat=function dateFormat(fmt, date) {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}

 
var hasPermi= function(key) {
	var perms = uni.getStorageSync('perms');
	var permList=JSON.parse(perms);
	if(permList[0]=="*:*:*"){
		return true;
	}
	var flag=false;
	permList.forEach(function(item, index, array) {
		 if(key==item)
		 {
			 flag=true;
		 }
	});
	return flag;
}
function isNumber(num){
	    //var reg = new RegExp("^[0-9]*$");
		var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
	    if(!reg.test(num)){
        return false;
    }
	return true;
}
function addOrReduceDate(type,date,num) {
	var nowDate = null;
	var strDate = "";
	num = parseInt(num); // 防止传入字符串报错
	var seperator1 = "-";
	var seperator2 = ":";
	if(date == "") {
		nowDate = new Date();
	} else {
		nowDate = new Date(date);
	}
	
	if(type==="Y"){
		nowDate.setFullYear(nowDate.getFullYear() + num);
	}
	if(type==="M"){
		nowDate.setMonth(nowDate.getMonth() + num);
	}
	if(type==="D"){
		nowDate.setDate(nowDate.getDate() + num);
	}
	if(type==="A"){
		nowDate.setFullYear(nowDate.getFullYear() + num);
		nowDate.setMonth(nowDate.getMonth() + num);
		nowDate.setDate(nowDate.getDate() + num);
	}
	var year = nowDate.getFullYear(); // 年
	var month = nowDate.getMonth() + 1; // 月
	strDate = nowDate.getDate(); //日
	var hours = nowDate.getHours(); // 时
	var minutes = nowDate.getMinutes(); // 分
	var seconds = nowDate.getSeconds(); // 秒
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	if(seconds >= 0 && seconds <= 9) {
		seconds = "0" + seconds;
	}
	var dateStr = year + seperator1 + month + seperator1 + strDate ;
	//+ " " + hours + seperator2 + minutes + seperator2 + seconds
	console.log(dateStr)
	return dateStr;
}
module.exports = {
        isEmpty : isEmpty,
		checkLoginState : checkLoginState,
		getDictLabelName:getDictLabelName,
		photosToArr:photosToArr,
		dateFormat:dateFormat,
		hasPermi:hasPermi,
		addOrReduceDate:addOrReduceDate,
		isNumber:isNumber
		
};